﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Models.Models;
using Services;


namespace BibliotecaWeb.Controllers
{ 
    public class ClienteController : Controller
    {
        private GerenciadorCliente gCliente;
     
        public ClienteController()
        {
            gCliente = new GerenciadorCliente();
        }
        //
        // GET: /Cliente/

        public ViewResult Index()
        {
            return View(gCliente.ObterTodos());
        }

        //
        // GET: /Cliente/Details/5

        public ViewResult Details(int id)
        {
            Cliente cliente = gCliente.Obter(id);
            return View(cliente);
        }

        //
        // GET: /Cliente/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Cliente/Create

        [HttpPost]
        public ActionResult Create(Cliente clienteModel)
        {
            if (ModelState.IsValid)
            {
                gCliente.Inserir(clienteModel);
                return RedirectToAction("Index");  
            }

            return View(clienteModel);
        }
        
        //
        // GET: /Cliente/Edit/5
 
        public ActionResult Edit(int id)
        {

            Cliente cliente = gCliente.Obter(id);
            return View(cliente);
        }

        //
        // POST: /Cliente/Edit/5

        [HttpPost]
        public ActionResult Edit(Cliente clienteModel)
        {
            if (ModelState.IsValid)
            {
                gCliente.Editar(clienteModel);
                return RedirectToAction("Index");
            }
            return View(clienteModel);
        }

        //
        // GET: /Cliente/Delete/5
 
        public ActionResult Delete(int id)
        {
            Cliente autoModel = gCliente.Obter(id);
            return View(autoModel);
        }

        //
        // POST: /Cliente/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            gCliente.Remover(id);
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
        }
    }
}